using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

/// <summary>
/// 挂载到UI界面上
/// </summary>
public class AudioView : BasePanel
{
    [SerializeField] private Slider volumeSliderBGM;
    [SerializeField] private Slider volumeSliderSFX;
    [SerializeField] private Button exit;
    
    /// <summary>
    /// 每次激活时
    /// 读取 AudioData 更新视图
    /// </summary>
    private void OnEnable()
    {
        volumeSliderBGM.value = AudioData.Instance.GetAudioVolumeBGM;
        volumeSliderSFX.value = AudioData.Instance.GetAudioVolumeSFX;
    }

    private void Start()
    {
        // 确保 Slider 的交互功能已启用
        volumeSliderBGM.interactable = true;
        volumeSliderSFX.interactable = true;
        
        
        volumeSliderBGM.onValueChanged.AddListener(value =>
        {
            if (AudioData.Instance != null)
            {
                AudioData.Instance.UpdateBGMVolume(value);
            }
        });
        volumeSliderSFX.onValueChanged.AddListener(value =>
        {
            if (AudioData.Instance != null)
            { 
                AudioData.Instance.GetAudioVolumeSFX = value;
            }
        });
         
        exit.onClick.AddListener(() =>
        {
            if (SceneManager.GetActiveScene().buildIndex == 1)
            {
                UIManager.Instance.OpenPanel(UIConst.GAMEMENU);
            }
            UIManager.Instance.ClosePanel(UIConst.SETTING);
        });
    }
}
